package com.uubx.controller;

import com.alibaba.druid.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.uubx.converter.DateConverter;
import com.uubx.pojo.Customer;
import com.uubx.result.Result;
import com.uubx.result.ResultUtils;
import com.uubx.service.CustomerService;
import com.uubx.vo.CustomerOrderVo;
import com.uubx.vo.CustomerPolicyVo;
import com.uubx.vo.CustomerVo;
import com.uubx.vo.PolicyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/customer")
@ResponseBody
@Api(description = "客户表相关接口")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @RequestMapping(value = "/listAll",method = RequestMethod.GET)
    @ApiOperation(value = "点击客户列表，查询出所有的数据",notes = "点击客户列表，查询出所有的数据",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result queryAll(){
        List<Map> maps = customerService.queryCustomerAll();
        return  ResultUtils.buildSuccess(maps,null);
    }


    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value = "点击客户列表，查询出所有的数据,输入当前页，分页大小",notes = "点击客户列表，查询出所有的数据,输入当前页，分页大小",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result list( CustomerVo customerVo){
        customerVo.setStartIndex((customerVo.getStartIndex()-1)*customerVo.getPageSize());
        customerVo.setPageSize(customerVo.getPageSize());
         List<Map> maps = customerService.queryCustomerByPage(customerVo);
         return  ResultUtils.buildSuccess(maps,null);
    }



    @RequestMapping(value = "/customerMessage",method = RequestMethod.GET)
    @ApiOperation(value = "点击查看详情，查询出客户信息",notes = "点击查看详情，查询出客户信息",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result customerMessage(Integer id){
        Customer customer = customerService.queryCustomerMessage(id);
        return ResultUtils.buildSuccess(customer);


    }



    @RequestMapping(value = "/customerCar",method = RequestMethod.GET)
    @ApiOperation(value = "点击查看详情，查看客户的车辆信息",notes = "点击查看详情，查看客户的车辆信息",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result customerCar(Integer id){
        List<Map> maps = customerService.queryCustomerCar(id);
        return ResultUtils.buildSuccess(maps);


    }



    @RequestMapping(value = "/customerBank",method = RequestMethod.GET)
    @ApiOperation(value = "点击查看详情查看客户的银行卡信息信息",notes = "点击查看详情查看客户的银行卡信息信息",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result customerBank(Integer id){
        List<Map> maps = customerService.queryCustomerBank(id);
        return ResultUtils.buildSuccess(maps);


    }



    @RequestMapping(value = "/queryCustomerByHolder",method = RequestMethod.POST)
    @ApiOperation(value = "查询某个客户名字模糊查询信息",notes = "查询某个客户名字模糊查询信息",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result queryCustomerByHolder(@RequestBody CustomerVo customerVo){
        customerVo.setStartIndex((customerVo.getStartIndex()-1)*customerVo.getPageSize());
        customerVo.setPageSize(customerVo.getPageSize());
         if (!StringUtils.isEmpty(customerVo.getHolder()))
        {
            customerVo.setHolder("%"+customerVo.getHolder()+"%");
        }

         List<Map> maps = customerService.queryCustomerByHolder(customerVo);
        return ResultUtils.buildSuccess(maps);
    }



    @RequestMapping(value = "/queryCustomerByPhone",method = RequestMethod.POST)
    @ApiOperation(value = "查询某个客户号码精确查询信息",notes = "查询某个客户号码精确查询信息",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result queryCustomerByPhone(@RequestBody CustomerVo customerVo){
        //CustomerVo customerVo=new CustomerVo();
        //customerVo.setStartIndex((page-1)*limit);
        //customerVo.setPageSize(limit);
        //customerVo.setAuthenticationId(authenticationId);
        //customerVo.setPhoneNumber(phone);
        customerVo.setStartIndex((customerVo.getStartIndex()-1)*customerVo.getPageSize());
        customerVo.setPageSize(customerVo.getPageSize());



        List<Map> maps = customerService.queryCustomerByPhone(customerVo);
        return ResultUtils.buildSuccess(maps);
    }





    @RequestMapping(value = "/queryCustomerByIdcard",method = RequestMethod.POST)
    @ApiOperation(value = "查询某个客户证件号码精确查询信息",notes = "查询某个客户证件号码精确查询信息",httpMethod = "post")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result queryCustomerByIdcard(@RequestBody CustomerVo customerVo){
        //CustomerVo customerVo=new CustomerVo();
        customerVo.setStartIndex((customerVo.getStartIndex()-1)*customerVo.getPageSize());
        customerVo.setPageSize(customerVo.getPageSize());
        //customerVo.setAuthenticationId(authenticationId);
        //customerVo.setIdCardNumber(idcard);

        List<Map> maps = customerService.queryCustomerByIdcard(customerVo);
        return ResultUtils.buildSuccess(maps);
    }


    @RequestMapping(value = "/queryPolicy",method = RequestMethod.POST)
    @ApiOperation(value = "查询保单信息",notes = "查询保单信息",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result Policy(@RequestBody CustomerPolicyVo policyVo) throws ParseException {

        PageHelper.offsetPage(policyVo.getStartIndex(),policyVo.getPageSize());
//        List<Map> list = oderService.findOderWhere(oderVo);
//        PageInfo<Map> pageInfo=new PageInfo<>(list);
        List<Map> maps = customerService.queryPolicy(policyVo);
        PageInfo<Map> pageInfo=new PageInfo<>(maps);
        return ResultUtils.buildSuccess(pageInfo);


    }
    @RequestMapping(value = "/queryCustomerOrder",method = RequestMethod.POST)
    @ApiOperation(value = "查询某个客户证件号码精确查询信息",notes = "查询某个客户证件号码精确查询信息",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功! data代表返回的数据"),
            @ApiResponse(code=500,message="后台逻辑错误!"),
            @ApiResponse(code=404,message="找不到页面!"),
            @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get!"),
            @ApiResponse(code=406,message="页面地址和接口名冲突!"),
            @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串!")
    })
    public Result queryOrder(@RequestBody  CustomerOrderVo customerOrderVo){
        PageHelper.offsetPage(customerOrderVo.getStartIndex(), customerOrderVo.getPageSize());
        List<Map> maps = customerService.queryOrder(customerOrderVo);
        PageInfo<Map> pageInfo = new PageInfo<>(maps);

//        customerOrderVo.setStartIndex((customerOrderVo.getStartIndex()-1)*customerOrderVo.getPageSize());
//        customerOrderVo.setPageSize(customerOrderVo.getPageSize());

        //List<Map> maps = customerService.queryOrder(customerOrderVo);
        return ResultUtils.buildSuccess(pageInfo);
    }





}
